<template>
<!-- 二手详情确认 -->
<div>
  <!-- <image class="pageImg" src="root:img/page/13.png" /> -->
  <head title="Order details"></head>
  <text class="waitTime" v-if="isLoading">Please wait a moment...</text>
  <div class="pageContent">
    <div class="orderDetail">
      <div class="order_top">
        <image class="googPic" :src="goodInfo.thumb" resize="cover" />
        <div class="goods_info">
          <text class="goods_title">{{goodInfo.title}}</text>
          <div class="goods_spec">
            <div class="priceInfo">
              <text class="symbol">AU$</text>
              <text class="money">{{goodInfo.price}}</text>
            </div>
          </div>
        </div>
      </div>
    </div>

    <div class="messagebox mt20" @click="setAddress" v-if="take_type!=1">
      <div class="locationBox row jbew atop">
        <text class="meth_title locaTit">Address</text>
        <div class="meth_right row jend acen">
          <text
            class="cityName"
            v-if="addressData.id"
          >{{addressData.address}} ,{{addressData.area}} ,{{addressData.city}} ,{{addressData.province}} {{addressData.postal_code}}</text>
          <text class="cityName" v-if="!addressData.id">Set place</text>
          <text class="rightIcon">&#xe6a1;</text>
        </div>
      </div>
      <!-- <div class="locationBox row jbew atop ">
					<text class="meth_title locaTit">Address</text>
					<div class="meth_right   row jend atop">
						<text class="cityName">{{addressData.address}}</text>
						<text class="rightIcon">&#xe6a1;</text>
					</div>
      </div>-->
    </div>
    <div class="methodBox row jbew acen">
      <text class="meth_title">Shipping method</text>
      <div class="meth_right row jend acen" @click="showMask=true;alertType='post'">
        <!-- <text class="shipping">{{take_type}}</text> -->
        <text class="shippingMoney" v-if="take_type!=1">AU${{totalPostage}}</text>
        <text class="shippingMoney" v-if="take_type==1">Local pick up</text>
        <text class="rightIcon">&#xe6a1;</text>
      </div>
    </div>
    <div class="methodBox row jbew acen mt20" @click="showMask=true;alertType='vacht'">
      <text class="meth_title">Vouchers</text>
      <div class="meth_right row jend acen">
        <!-- <text class="shipping">{{selected.label}}</text> -->
        <text class="shippingMoney" v-if="couponPrice">AU$ {{couponPrice }}</text>
        <text class="rightIcon">&#xe6a1;</text>
      </div>
    </div>
    <div class="footer">
      <div class="settlement">
        <div class="sum">
          <text class="sumTitle">Order total:</text>
          <text class="symbol">AU$</text>
          <text class="money">{{totalPrice}}</text>
        </div>
        <text class="btn" @click="getOrderPay">Confirm</text>
      </div>
    </div>
  </div>

  <wxc-popup
    :height="getScreenHeight()-400"
    pos="bottom"
    ref="wxcpopup"
    :show="showMask"
    popup-color="transparent"
    @wxcPopupOverlayClicked="showMask=false"
  >
    <!-- 邮费弹出框 -->
    <div class="shopAlert" v-if="alertType=='post'">
      <text class="alertTop">Shipping method</text>
      <scroller class="alertScroll">
        <div class="radioLi" v-if="goodInfo.take_type.indexOf('2')!=-1">
          <div class="radioLiBox" @click="changeTake(2)">
            <text
              class="liIcon"
              :class="[take_type==2?'selected':'']"
            >{{take_type==2?"&#xe602;":"&#xe67f;"}}</text>
            <text class="liTxt" :class="[take_type==2?'selected':'']">Australia post</text>
          </div>
        </div>
        <div class="radioLi" v-if="goodInfo.take_type.indexOf('3')!=-1">
          <div class="radioLiBox" @click="changeTake(3)">
            <text
              class="liIcon"
              :class="[take_type==3?'selected':'']"
            >{{take_type==3?"&#xe602;":"&#xe67f;"}}</text>
            <text class="liTxt" :class="[take_type==3?'selected':'']">Giv delivery</text>
          </div>
          <div class="iconqsBox" @click="showPropOver('methPropc')">
            <image class="iconqs" src="root:img/iconQS.png" resize="contain" />
          </div>
        </div>
        <div class="radioLi" v-if="goodInfo.take_type.indexOf('1')!=-1">
          <div class="radioLiBox" @click="changeTake(1)">
            <text
              class="liIcon"
              :class="[take_type==1?'selected':'']"
            >{{take_type==1?"&#xe602;":"&#xe67f;"}}</text>
            <text class="liTxt" :class="[take_type==1?'selected':'']">Local pick up</text>
          </div>
        </div>
      </scroller>
    </div>
    <scroller class="shopAlert" v-if="alertType=='vacht'">
      <empty
        v-if="couponValidList.length==0"
        tips="Your vouchers is empty"
        img="root:img/e_eva.png"
      ></empty>
      <div class="rowcell" v-for="(row,index) in couponValidList" :key="index">
        <div class="cellBox">
          <div class="boxleft">
            <text class="money">AU$ {{row.reduce}}</text>
            <text class="title">{{row.name}}</text>
            <text class="term">{{row.start_time}} ~ {{row.end_time}}</text>
          </div>
          <text class="line"></text>
          <div class="right">
            <text class="touse" @click="is_coupon='1';getOrderConfirm()">USE</text>
          </div>
        </div>
      </div>
    </scroller>
  </wxc-popup>
</div>
</template>

<script>
const selectAddress = new BroadcastChannel("selectAddress");
const creatAddress = new BroadcastChannel("creatAddress");
import {
  get_goods_info,
  get_orderConfirm,
  get_address_list,
  get_order_pay,
  get_users_coupon_list
} from "../../mixin/ajax.js";
import asCore from "../../mixin/core";
import Utils from "../../mixin/utils";
import { WxcPopup } from "weex-ui";
export default {
  components: { WxcPopup },
  data() {
    return {
      //是否显示遮罩层
      showMask: false,
      couponValidList: [],
      take_type: "",
      couponPrice: "",
      totalPrice: "", //总价
      alertType: "",
      totalPostage: "", //总邮费
      co_order_id: "",
      selected: {
        value: "1",
        label: "Australia post"
      },
      shippWay: [
        {
          value: "1",
          label: "Australia post"
        },
        {
          value: "2",
          label: "Giv delivery"
        },
        {
          value: "3",
          label: "Local pick up"
        }
      ],
      is_coupon: "",
      goodInfo: {
        thumb: "",
        title: "",
        price: ""
      },
      addressData: {},
      sumPrice: "52.30",
      goods_title: " ",
      activity: ""
    };
  },

  created() {
    selectAddress.onmessage = this.changeAddress;
    creatAddress.onmessage = this.getList;
  },
  methods: {
    onLoad(param) {
      if (param && param.param) {
        return false;
      }
      let that = this;
      if (param.activity) {
        this.activity = "activity";
      }
      if (param && param.id) {
        this.goodId = param.id;
        asCore.getBsessionid(userId => {
          that.userId = userId;
          that.getGoodInfo();
          that.getList();
          that.getCoupon();
        });
      }
    },

    getCoupon() {
      get_users_coupon_list(
        { users_id: this.userId, status: "1" },

        (res, flag) => {
          if (flag) {
            if (res.code == 200) {
              this.couponValidList = res.data;
            }
          }
        }
      );
    },

    getOrderConfirm() {
      if (this.showMask) {
        this.$refs.wxcpopup.hide();
      }
      this.isLoading = true;
      let address_id = this.addressData.id;
      if (this.take_type == 1) {
        address_id = "";
      }
      get_orderConfirm(
        {
          users_id: this.userId,
          order_id: "",
          goods_id: this.goodId,
          number: 1,
          take_type: this.take_type,
          address_id: address_id,
          is_coupon: this.is_coupon
        },
        (res, flag) => {
          this.isLoading = false;

          if (flag) {
            if (res.code == 200) {
              if (this.activity) {
                this.totalPrice = res.data.info.pay_price;
                this.totalPostage = res.data.info.postage;
                this.co_order_id = res.data.info.id;
              } else {
                this.totalPrice = res.data.total.pay_price;
                this.totalPostage = res.data.total.total_postage;
                this.couponPrice = res.data.total.coupon_price;
                this.co_order_id = res.data.total.co_order_id;
              }
            } else {
              this.toast(res.message);
            }
          }
        },
        this.activity
      );
    },
    changeTake(data) {
      if (data) {
        this.take_type = data;
      }

      this.getOrderConfirm();
      this.$refs.wxcpopup.hide();
    },

    getOrderPay() {
      let that = this;
      this.isLoading = true;
      get_order_pay(
        {
          users_id: this.userId,
          co_order_id: this.co_order_id,
          order_id: this.co_order_id,
          is_pay: 1
        },
        (res, flag) => {
          this.isLoading = false;
          if (flag) {
            if (res.code == 200) {
              let url = "root:app/pay/web.js";
              if (Utils.env.isWeb()) {
                url = "root:app/pay/payment.js";
              }
              this.push(url, {
                id: res.data.id,
                amount: res.data.pay_price,
                userId: that.userId,
                activity: that.activity
              });
            } else {
              this.toast(res.message);
            }
          }
        },
        this.activity
      );
    },
    getList() {
      let that = this;
      var pref = weex.requireModule("storage");
      pref.getItem("defaultAddress", event => {
        if (event.result == "success") {
          that.addressData = JSON.parse(event.data);
        }
      });
    },

    getGoodInfo() {
      get_goods_info(
        { users_id: this.userId, id: this.goodId },
        (res, flag) => {
          if (flag) {
            if (res.code == "200") {
              this.goodInfo = Object.assign({}, this.goodInfo, res.data);
              if (this.activity) {
                this.take_type = "2,3";
              } else {
                this.take_type = res.data.take_type[0];
              }

              this.getOrderConfirm();
            }
          }
        },
        this.activity
      );
    },
    changeAddress(msg) {
      this.addressData = msg.data;
    },

    setAddress() {
      this.push("root:app/user/address/address.js", {
        type: "shop"
      });
    }
  }
};
</script>

<style scoped>
.pageImg {
  width: 750px;
  height: 1334px;
}

.pageContent {
  /* margin-top: -1334px; */
  background-color: #f2f2f2;
  flex: 1;
  width: 750px;
}

.mt20 {
  margin-top: 20px;
}

.orderDetail {
  padding: 30px;
  background-color: #fff;
}
.maskClack {
  position: fixed;
  left: 0;
  bottom: 0;
  right: 0;
  top: 0;
  justify-content: center;
  align-items: center;
  background-color: transparent;
}
.indicator {
  width: 40px;
  height: 40px;
}
.order_top {
  flex: 1;
  flex-direction: row;
  border-bottom-style: solid;
  border-bottom-color: #e6e6e6;
  border-bottom-width: 2px;
  padding-bottom: 40px;
}

.googPic {
  width: 220px;
  height: 220px;
}

.goods_info {
  height: 220px;
  padding-left: 30px;
  flex: 1;
  justify-content: space-between;
}

.goods_title {
  font-size: 28px;
  line-height: 36px;
}

.goods_spec {
  padding-top: 30px;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 0;
}

.priceInfo {
  flex-direction: row;
  align-items: center;
}

.specInfo {
  height: 42px;
  justify-content: space-between;
  padding: 0 5px;
  align-items: center;
  border-width: 1px;
  border-style: solid;
  border-color: #e6e6e6;
  flex-direction: row;
  /* background-color: #f2f22f; */
}

.specText {
  font-size: 22px;
  height: 40px;
  line-height: 40px;
  margin-left: 10px;
  margin-right: 25px;
  color: #999;
}

.iconDown {
  font-size: 22px;
  font-family: iconfont;
  line-height: 40px;
  color: #999;
}

.methodBox {
  width: 750px;
  height: 100px;
  margin-top: 20px;
  margin-bottom: 20px;
  padding: 0 32px;
  background-color: #fff;
}
.methodBox:active {
  background-color: #f2f2f2;
}
.radioLi {
  width: 686px;
  margin-top: 30px;
  flex-direction: row;
  align-items: center;
}
.radioLiBox {
  flex-direction: row;
  align-items: center;
}
.messagebox {
  width: 750px;
  padding: 0 30px;
  background-color: #fff;
}

.locationBox {
  width: 690px;

  /* 	border-bottom-style: solid;
		border-bottom-color: #e6e6e6;
		border-bottom-width: 2px; */
  padding: 30px 0;
}

.meth_title {
  color: #323232;
  font-size: 30px;
}

.locaTit {
  width: 230px;
}

.meth_right {
  flex: 1;
}

.shipping {
  margin-right: 30px;
  font-size: 30px;
  color: #999999;
}

.cityName {
  margin-right: 30px;
  font-size: 30px;
  color: #666666;
  flex: 1;
  text-align: right;
}

.shippingMoney {
  color: #ed404c;
  font-size: 30px;
  margin-right: 30px;
}

.rightIcon {
  font-family: iconfont;
  font-size: 26px;
  color: #999;
}

.row {
  flex-direction: row;
}

.jbew {
  justify-content: space-between;
}

.jend {
  justify-content: flex-end;
}

.atop {
  align-items: flex-start;
}

.acen {
  align-items: center;
}

.footer {
  width: 750px;
  background-color: #ffffff;
  height: 100px;
  justify-content: flex-end;
  align-items: center;
  font-size: 28px;
  position: fixed;
  bottom: 0px;
}

.settlement {
  width: 750px;
  height: 100px;
  justify-content: space-between;
  align-items: center;
  flex-direction: row;
}

.sum {
  flex: 1;
  font-size: 28px;
  padding-left: 30px;
  justify-content: flex-start;
  flex-direction: row;
  align-items: center;
}
.waitTime {
  font-size: 30px;
  text-align: center;
  padding: 20px;
  color: #999999;
}
.sumTitle {
  font-size: 30px;
  margin-right: 20px;
}

.symbol {
  color: #ed404c;
}

.money {
  font-weight: 600;
  color: #ed404c;
  font-size: 36px;
}

.btn {
  width: 230px;
  height: 100px;
  line-height: 100px;
  background-color: #303030;
  color: #fff;
  text-align: center;
  font-size: 30px;
}

.hidemask {
  height: 0;
}

.maskAlert {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 456px;
  top: 0;
  /* background-color: rgba(0, 0, 0, 0); */
}

.shopAlert {
  flex: 1;
  background-color: #ffffff;
  border-top-left-radius: 20px;
  border-top-right-radius: 20px;
  align-items: center;
  padding: 32px;
}

.alertTop {
  width: 686px;
  text-align: left;
  padding-bottom: 32px;
  font-size: 28px;
  color: #333333;
}

.alertScroll {
  flex: 1;
}

.selectLi {
  /* margin-bottom: 30px; */
  height: 70px;
  flex-direction: row;
  align-items: center;
  justify-content: flex-start;
  width: 750px;
  padding-left: 32px;
}

.liIcon {
  font-size: 40px;
  font-family: iconfont;
  color: #999999;
  margin-right: 10px;
}

.liTxt {
  color: #999999;
  font-size: 28px;
}

.selected {
  color: #ba8833;
}

.sureBtn {
  width: 686px;
  height: 80px;
  line-height: 80px;
  border-radius: 10px;
  margin-bottom: 14px;
  background-color: #303030;
  color: #fff;
  text-align: center;
  font-size: 30px;
}
.btn:active {
  background-color: #000;
}
.sureBtn:active {
  background-color: #000;
}

.rowcell {
  width: 686px;
  /* height: 150px; */
  padding: 16px 0;
  border-radius: 8px;
  background-color: #f2f2f2;
}

.cellBox {
  flex: 1;
  width: 686px;
  height: 150px;
  align-items: center;
  flex-direction: row;
  background-color: #f2f2f2;
  position: relative;
}

.line {
  height: 118px;
  border-left-width: 2px;
  border-left-color: #999;
  border-left-style: dashed;
}

.boxleft {
  flex: 1;
  height: 150px;
  position: relative;
  padding-left: 32px;
  justify-content: center;
  border-radius: 16px;
  background-color: #f2f2f2;
}

.money {
  color: #ec414d;
  font-size: 40px;
}

.title {
  margin: 10px 0;
  font-size: 23px;
  color: #666666;
}

.term {
  font-size: 18px;
  color: #999;
}

.right {
  width: 170px;
  height: 150px;
  align-items: center;
  justify-content: center;
  /* 	border-left-width: 1px;
		border-left-color: #000000;
		border-left-style: dashed; */
  background-color: #f2f2f2;
  border-radius: 16px;
}

.touse {
  color: #ffffff;
  background-image: linear-gradient(to right, #d2b37c, #ba8833);
  font-size: 26px;
  width: 112px;
  height: 54px;
  line-height: 54px;
  text-align: center;
  border-radius: 4px;
}
</style>
